﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Wage_WageClearing : ATPages
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Function f = new Function();
        if (!IsPostBack)
        {

            ZSql js = new ZSql();
            hfxs.Value = Request.QueryString["moduid"].ToString();
            lblPath.Text = f.getModuleidAdd(Request["moduid"]);
            hfgetId.Value = Request.QueryString["SalesId"].ToString();
            hfgetTim.Value = Request.QueryString["modul"].ToString();
            Hfname.Value = Request.QueryString["StaffName"].ToString();
            cleaTime.Text = DateTime.Now.ToShortDateString();
            lblName.Text = Server.UrlDecode(Request.Cookies["user"].Values["name"]);
            WStaffSalary.Attributes["contentEditable"] = "false";
            salemenoy.Attributes["contentEditable"] = "false";
            WYWage.Attributes["contentEditable"] = "false";
            WSWage.Attributes["contentEditable"] = "false";
            //riqi.Attributes["contentEditable"] = "false";
            if (hfgetId.Value != "" && hfgetTim.Value != "")
            {
                js.Open("select a.userId,a.SalesId,b.StaffName,d.Deptname,b.StaffSalary ,a.comodName,a.modul,a.Unit,a.Prices,a.number,a.TotalMoney,(convert(char(10),C_date,120))as C_date,b.StaffId,d.Deptid from  CS_Staff as b join CS_Sales as a on a.Saleman=b.StaffId  join Department as d on b.deptid=d.deptid  where a.SalesId=" + hfgetId.Value + " order by d.Deptid desc");

                if (js.m_table.Rows.Count > 0)
                {
                    WStaffName.Text = js.m_table.Rows[0]["StaffName"].ToString();
                    WStaffSalary.Text = js.m_table.Rows[0]["StaffSalary"].ToString().Substring(0, js.m_table.Rows[0]["StaffSalary"].ToString().Length - 2);
                    department.Text = js.m_table.Rows[0]["Deptname"].ToString();
                    lblydate.Text = js.m_table.Rows[0]["C_date"].ToString();
                    comodName.Text = js.m_table.Rows[0]["comodName"].ToString();
                    modul.Text = js.m_table.Rows[0]["modul"].ToString();
                    Unit.Text = js.m_table.Rows[0]["Unit"].ToString();
                    Prices.Text = js.m_table.Rows[0]["Prices"].ToString().Substring(0, js.m_table.Rows[0]["Prices"].ToString().Length - 2);
                    number.Text = js.m_table.Rows[0]["number"].ToString();
                    salemenoy.Text = js.m_table.Rows[0]["TotalMoney"].ToString().Substring(0, js.m_table.Rows[0]["TotalMoney"].ToString().Length - 2);
                    //WYWage.Text = js.m_table.Rows[0]["StaffSalary"].ToString().Substring(0, js.m_table.Rows[0]["StaffSalary"].ToString().Length - 2);
                    //WSWage.Text = js.m_table.Rows[0]["StaffSalary"].ToString().Substring(0, js.m_table.Rows[0]["StaffSalary"].ToString().Length - 2);
                    riqi.Visible = false;
                    js.Close();
                }
                else
                {
                    Response.Write("<script>alert('没有员工信息或员工销售数据');location.href=document.referrer</script>");
                }

            }

            if (hfgetId.Value == "" && hfgetTim.Value == "")
                {
                    js.Open("select a.userId,b.StaffName,d.Deptname,b.StaffSalary ,a.comodName,a.modul,a.Unit,a.Prices,a.number,a.TotalMoney,(convert(char(10),C_date,120))as C_date,u.StaffId,d.Deptid from  CS_Staff as b  left join UserInfo as u on  b.StaffId=u.StaffId left join CS_Sales as a on a.Saleman=u.StaffId  left join Department as d on b.deptid=d.deptid  where b.StaffName='" + Hfname.Value + "' order by d.Deptid desc ");
                    if (js.m_table.Rows.Count > 0)
                    {
                        WStaffName.Text = js.m_table.Rows[0]["StaffName"].ToString();
                        WStaffSalary.Text = js.m_table.Rows[0]["StaffSalary"].ToString().Substring(0, js.m_table.Rows[0]["StaffSalary"].ToString().Length - 2);
                        department.Text = js.m_table.Rows[0]["Deptname"].ToString();
                        comodName.Text = "无";
                        modul.Text = "无";
                        Unit.Text = "无";
                        Prices.Text = "0.00";
                        number.Text = "0";
                        salemenoy.Text = "0.00";
                        //WYWage.Text = js.m_table.Rows[0]["StaffSalary"].ToString().Substring(0, js.m_table.Rows[0]["StaffSalary"].ToString().Length - 2);
                        //WSWage.Text = js.m_table.Rows[0]["StaffSalary"].ToString().Substring(0, js.m_table.Rows[0]["StaffSalary"].ToString().Length - 2);
                        riqi.Visible = false;   
                        rq.Text = "结算日期：";
                        lblydate.Visible = false;
                        riqi.Visible = true;
                        riqi.Attributes.Add("onclick", "SelectDate('riqi')");
                        js.Close();
                    }
                    else
                    {
                        Response.Write("<script>alert('没有员工信息或员工销售数据');location.href=document.referrer</script>");
                    }



            }
            

        }
    }
 
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        ZSql bcdata = new ZSql();
        ZSql up = new ZSql();
        string jszt = hfgetId.Value;
//        int flag = 1;
        if (hfgetId.Value == "" && hfgetTim.Value == "")
        {
            if (riqi.Text == "")
            {
                Response.Write("<script>alert('结算日期不能为空');location.href=document.referrer</script>");

            }
            else
            {
                //up.Open("update CS_Sales set Isjs='1' where SalesId="+hfgetId.Value+"");
                bcdata.Open("insert into CS_Wages (WStaffName,department,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditState,AuditUserName,AuditDate) values('" + WStaffName.Text + "','" + department.Text + "','" + comodName.Text + "','" + modul.Text + "'," + WStaffSalary.Text + "," + WStaffPrice.Text + "," + WStaffPercentage.Text + "," + salemenoy.Text + "," + WYWage.Text + "," + WSWage.Text + "," + Wkc.Text + ",'" + Common.FormatParameter(riqi.Text) + "','" + jszt + "','" + lblName.Text + "','" + cleaTime.Text + "')");
            }

        }
        else
        {
            //up.Open("update CS_Sales set Isjs='1' where SalesId=" + hfgetId.Value + "");
            bcdata.Open("insert into CS_Wages (WStaffName,department,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditState,AuditUserName,AuditDate) values('" + WStaffName.Text + "','" + department.Text + "','" + comodName.Text + "','" + modul.Text + "'," + WStaffSalary.Text + "," + WStaffPrice.Text + "," + WStaffPercentage.Text + "," + salemenoy.Text + "," + WYWage.Text + "," + WSWage.Text + "," + Wkc.Text + ",'" + lblydate.Text + "','" + jszt + "','" + lblName.Text + "','" + cleaTime.Text + "')");
        }
        Response.Write("<script>window.location='wages.aspx?moduid=" + Request["moduid"] + "';</script>");

    }
}
